package com.mt.roll.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 服务网关swagger配置
 *
 * @author jiff
 * @date 2018/11/1
 * @since 1.0
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket passportApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-passport")
                .apiInfo(apiInfo("passport", "统一认证接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.passport"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket opcuaApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-opcua")
                .apiInfo(apiInfo("opcua", "opcua接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.opcua"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket commonApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-common")
                .apiInfo(apiInfo("common", "公共接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.common"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket upmsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-upms")
                .apiInfo(apiInfo("upms", "通用权限接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.upms"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket wmsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-wms")
                .apiInfo(apiInfo("wms", "wms接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.wms"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket processApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-process")
                .apiInfo(apiInfo("process", "工艺接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.process"))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean
    public Docket reportApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("roll-report")
                .apiInfo(apiInfo("report", "报表接口"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mt.roll.report"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo(String title, String description) {// 创建API的基本信息，这些信息会在Swagger UI中进行显示
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl("http://www.mt.com")
                .contact(new Contact("jiff", "", "jiff@ulabcare.com"))
                .version("1.0")
                .build();
    }
}
